package com.itqf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.mapper.GongYingDao;
import com.itqf.entity.GongYing;
import com.itqf.service.GongYingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author: Panjianwei
 * @date: 2019/12/18 22:04
 * 代码是一门艺术，需要我们细细用心品味！
 */
@Service
public class GongYingServiceImpl implements GongYingService {
    @Autowired
    private GongYingDao gongYingDao;
    @Override
    public PageInfo<GongYing> findall(String gName, String gLinkman,int pageindex,int pagesize) {
        HashMap map = new HashMap<>();
        map.put("gname",gName);
        map.put("glinkman",gLinkman);
//       1. 指定分页参数
        PageHelper.startPage(pageindex,pagesize);
//       2.调取查询方法
        List<GongYing> findall = gongYingDao.findall(map);
        for (GongYing gongYing : findall) {
            String gName1 = gongYing.getGName();
        }
//       3.封装pageinfo
        PageInfo<GongYing> pageInfo = new PageInfo(findall);
        return  pageInfo;
    }

    @Override
    public int addgongying(GongYing gongYing) {
        gongYing.setGStatu(1);
        return gongYingDao.addgongying(gongYing);
    }

    @Override
    public GongYing findbygId(int gId) {
        return gongYingDao.findbygId(gId);
    }
    @Override
    public int update(GongYing gongYing) {
        gongYing.setGCreateTime(new Date());
        return gongYingDao.update(gongYing);
    }

    @Override
    public int delete(int gId) {
        return gongYingDao.delete(gId);
    }
}
